<template>
  <div class="app-container">
    <doc-alert title="工作流" url="https://doc.iocoder.cn/bpm" />

    <!-- 搜索工作栏 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="学院" prop="collegeId">
        <!-- <el-input v-model="queryParams.collegeId" placeholder="请输入学院id" clearable @keyup.enter.native="handleQuery"/> -->
        <college-selector v-model="queryParams.collegeId"></college-selector>
      </el-form-item>
      <el-form-item label="审批状态" prop="approvalStatus">
        <el-select
          v-model="queryParams.approvalStatus"
          placeholder="请选择审批状态"
          clearable
          size="small"
        >
          <el-option
            v-for="dict in this.getDictDatas(
              DICT_TYPE.ATTENDANCE_APPROVAL_STATUS
            )"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="请假类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="请选择请假类型" clearable>
          <el-option v-for="dict in leaveTypeDictData" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item> -->
      <!-- <el-form-item label="申请时间" prop="createTime">
        <el-date-picker v-model="queryParams.createTime" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" />
      </el-form-item>
      <el-form-item label="结果" prop="result">
        <el-select v-model="queryParams.result" placeholder="请选择流结果" clearable>
          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.BPM_PROCESS_INSTANCE_RESULT)"
                     :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item> -->

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <!-- v-hasPermi="['bpm:oa-leave:create']" -->
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="open = true"
          >请假申请</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="学院" align="center" prop="collegeName" />
      <el-table-column label="姓名" align="center" prop="userName" />
      <el-table-column label="角色" align="center" prop="userType">
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.COLLEGE_USER_ROLE"
            :value="scope.row.userType"
          />
        </template>
      </el-table-column>
      <el-table-column label="联系方式" align="center" prop="userPhone" />
      <el-table-column label="请假天数" align="center" prop="leaveDays" />
      <el-table-column label="请假说明" align="center" prop="leaveExplain" />
      <!-- <el-table-column label="请假开始时间" align="center" prop="leaveExplain" /> -->
      <!-- <el-table-column label="状态" align="center" prop="result">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.BPM_PROCESS_INSTANCE_RESULT" :value="scope.row.result"/>
        </template>
      </el-table-column> -->
      <el-table-column
        label="请假开始时间"
        align="center"
        prop="leaveStartTime"
        width="165"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.leaveStartTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="请假结束时间"
        align="center"
        prop="leaveEndTime"
        width="165"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.leaveEndTime) }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="状态" align="center" prop="approvalStatus" /> -->
      <el-table-column label="状态" align="center" prop="approvalStatus">
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.ATTENDANCE_APPROVAL_STATUS"
            :value="scope.row.approvalStatus"
          />
        </template>
      </el-table-column>
      <!-- <el-table-column label="请假类型" align="center" prop="type">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.BPM_OA_LEAVE_TYPE" :value="scope.row.type"/>
        </template>
      </el-table-column>
      <el-table-column label="原因" align="center" prop="reason" />
      <el-table-column label="申请时间" align="center" prop="applyTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column> -->
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="110"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleQueryDetails(scope.row)"
            >查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
          <!-- @click="handleDetail(scope.row)"-->

          <!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleProcessDetail(scope.row)">审批进度</el-button>  -->
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog
      title="查看"
      append-to-body
      :visible.sync="dialogVisible"
      width="30%"
      :close-on-click-modal="false"
    >
      <el-row>
        <div class="group-name">基本信息</div>
        <el-col class="item" :span="12"
          >学院:{{ leaveDetail.collegeName }}</el-col
        >
        <el-col class="item" :span="12">姓名:{{ leaveDetail.userName }}</el-col>
        <el-col class="item" :span="12"
          >联系方式:{{ leaveDetail.userPhone }}</el-col
        >
        <el-col class="item" :span="12"
          >角色:<dict-tag
            :type="DICT_TYPE.COLLEGE_USER_ROLE"
            :value="leaveDetail.userType"
        /></el-col>
        <el-col class="item" :span="12"
          >请假天数:{{ leaveDetail.leaveDays }}天</el-col
        >
        <el-col class="item" :span="12"
          >请假开始时间:{{ leaveDetail.leaveStartTime }}</el-col
        >
        <el-col class="item" :span="12"
          >请假结束时间:{{ leaveDetail.leaveEndTime }}</el-col
        >
        <!-- <el-col class="item" :span="12">请假类型:{{leaveDetail.reasonName}}</el-col> -->
        <el-col class="item" :span="12"
          >状态:
          <dict-tag
            :type="DICT_TYPE.ATTENDANCE_APPROVAL_STATUS"
            :value="leaveDetail.approvalStatus"
          />
        </el-col>

        <el-col class="item" :span="12"
          >请假说明:{{ leaveDetail.leaveExplain }}</el-col
        >
      </el-row>
    </el-dialog>
    <leave-edit :show.sync="open" @success="getList"></leave-edit>
  </div>
</template>

<script>
import { getLeavePage, deleteLeave } from "@/api/teacherSide/leave";
import { getDictDatas, DICT_TYPE } from "@/utils/dict";
import { cancelProcessInstance } from "@/api/bpm/processInstance";
import CollegeSelector from "@/components/CollegeSelector";
import leaveEdit from "./formEdit.vue";
export default {
  name: "Leave",
  components: {
    CollegeSelector,
    leaveEdit,
  },

  data() {
    return {
      dialogVisible: false,
      open: false,
      show: false,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 请假申请列表
      list: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        userType: 3,
        approvalStatus: undefined,
        collegeId: undefined,
      },
      leaveDetail: {},
      // //搜索下拉所需
      // options: [],
      // value: [],
      // list: [],
      // loading: false,
      // // 请假类型
      // leaveTypeList:[],
      // // 表单校验
      // rules: {
      //   leaveStartTime: [
      //     { required: true, message: "开始时间不能为空", trigger: "blur" },
      //   ],
      //   leaveEndTime: [
      //     { required: true, message: "结束时间不能为空", trigger: "blur" },
      //   ],
      //   leaveDays: [
      //     { required: true, message: "请输入请假天数", trigger: "change" },
      //   ],
      //   copySendId: [
      //     { required: true, message: "请选择抄送人", trigger: "change" },
      //   ],
      //   reasonId: [{ required: true, message: "请假事由不能为空", trigger: "change" }],
      //   leaveExplain: [
      //     { required: true, message: "请假说明不能为空", trigger: "change" },
      //   ],
      // },
      typeDictData: getDictDatas(DICT_TYPE.BPM_OA_LEAVE_TYPE),
      leaveTypeDictData: getDictDatas(DICT_TYPE.BPM_OA_LEAVE_TYPE),
      leaveResultData: getDictDatas(DICT_TYPE.BPM_PROCESS_INSTANCE_RESULT),
    };
  },
  created() {
    this.getList();
    // this.getLeaveTypeList()
  },
  methods: {
    // /** 提交按钮 */
    // submitForm() {
    //   this.$refs["form"].validate((valid) => {
    //     if (!valid) {
    //       return;
    //     }
    //     console.log(this.createleave);
    //     createLeave({ ...this.createleave,userId:this.$store.getters.userId }).then((res) => {
    //       console.log("111111111", res);
    //        this.$modal.msgSuccess("提交成功");
    //        this.cancel()
    //        this.getList()
    //     });
    //   });
    // },
    // remoteMethod(query) {
    //   if (query !== "") {
    //     this.loading = true;
    //     teacherList({ findStr: query }).then((res) => {
    //       console.log("res", res);
    //       this.options = res.data;
    //       this.loading = false;
    //     });
    //   } else {
    //     this.options = [];
    //   }
    // },
    // getLeaveTypeList(){
    //   getLeaveType().then(res=>{
    //     this.leaveTypeList = res.data
    //   })
    // },
    // cancel() {
    //   this.show = false;
    //   this.createleave  = {
    //     leaveStartTime: undefined,
    //     leaveEndTime: undefined,
    //     leaveDays: undefined,
    //     leaveExplain: undefined,
    //     copySendId: undefined,
    //     reasonId:undefined
    //   }

    // },
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getLeavePage({
        ...this.queryParams,
        userId: this.$store.getters.userId,
      }).then((response) => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    handleQueryDetails(row) {
      console.log("res", row)
      this.leaveDetail = row;
      this.dialogVisible = true

    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },


    /** 查看审批进度的操作 */
    handleProcessDetail(row) {
      this.$router.push({
        path: "/bpm/process-instance/detail",
        query: { id: row.processInstanceId },
      });
    },
    /** 取消请假 */
    // handleCancel(row) {
    //   const id = row.id;
    //   this.$prompt("请输入取消原因？", "取消流程", {
    //     type: "warning",
    //     confirmButtonText: "确定",
    //     cancelButtonText: "取消",
    //     inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/, // 判断非空，且非空格
    //     inputErrorMessage: "取消原因不能为空",
    //   })
    //     .then(({ value }) => {
    //       return cancelProcessInstance(id, value);
    //     })
    //     .then(() => {
    //       this.getList();
    //       this.$modal.msgSuccess("取消成功");
    //     });
    // },
    handleDelete(row) {
      const id = row.id;
      this.$modal.confirm('确认删除?').then(() => {
        deleteLeave(id).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => { });
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
.group-name {
  padding: 10px;
  border-bottom: 1px solid #f5f5f5;
  margin-bottom: 20px;
  font-size: 16px;
  font-weight: bold;
}
.item {
  margin: 10px 0;
}
</style>

